import CustomTable from '@/components/custom-table/index.vue'
import {
  mapState,
  mapActions,
} from 'vuex'
import { TABLE_CLOUMNS } from './constants.js'

export default {
  name: '',
  components: {
    CustomTable
  },
  computed: {
    ...mapState('employees', ['list', 'permission', 'total'])

  },
  methods: {
    ...mapActions('employees', ['updateList', 'updatePermission']),
    btnPropsMapper(scope, key) {
      const { level } = scope.row
      return {
        type: 'text',
        size: 'small',
        disabled: !this.permission[level].includes(key)
      }
    },
    onEvent(eventType, ...args) {
      switch (eventType) {
        case 'current-change':
          this.onCurrentPageChange(...args)
          break
        case 'size-change':
          this.onPageSizeChange(...args)
          break
        case 'btn-click':
          this.onBtnClick(...args)
          break
        default:
          console.error('不受支持的事件类型')
          break
      }
    },
    onCurrentPageChange(currentPage) {
      this.params.page = currentPage
      this.updateList(this.params)
    },
    onPageSizeChange(currentSize) {
      this.params.size = currentSize
      this.params.page = 1
      this.updateList(this.params)
    },
    onBtnClick(btnKey, row, e) {
      switch (btnKey) {
        case 'detail':
          this.onDetail(row)
          break
        case 'regular':

          break
        case 'transfer':

          break
        case 'dimisstion':

          break
        case 'role':

          break
        case 'delete':
          break
        default:
          break
      }
    },
    onDetail(row) {
      console.log('on detail', row)
    }
  },
  props: {

  },
  data() {
    return {
      TABLE_CLOUMNS, // 数据
      params: {
        page: 1,
        size: 10
      }
    }
  },
  mounted() {
    this.updateList(this.params)
    this.updatePermission()
  },
  created() {

  }
}
